<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
            "http://www.w3.org/TR/REC-html40/loose.dtd">
<HTML>
<HEAD>



<META http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<META name="GENERATOR" content="hevea 1.08">
<LINK rel="stylesheet" type="text/css" href="embroot.css">
<TITLE>
Type conversion between Tcl and ECLiPSe
</TITLE>
</HEAD>
<BODY >
<A HREF="embroot023.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="embroot016.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="embroot025.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
<HR>

<H2 CLASS="section"><A NAME="htoc45">5.8</A>&nbsp;&nbsp;Type conversion between Tcl and ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP></H2>
<A NAME="secexdrtcl"></A>

EXDR (ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> External Data Representation, see also chapter
<A HREF="embroot049.html#chapexdr">9</A>) is a data encoding that allows to represent a
significant subset of the ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> data types. The following Tcl
primitives are provided to handle EXDR-format:
<DL CLASS="description" COMPACT=compact><DT CLASS="dt-description">
<A NAME="ecwriteexdr"></A><A NAME="@default106"></A><B>ec_write_exdr <I>channel data ?format?</I></B><DD CLASS="dd-description"><BR>
write an EXDR-term onto the given channel.
 The term is constructed using the <I>data</I> argument and
 the additional type information provided in the <I>format</I>
 argument. If no format is specified, it defaults to S (string).<BR>
<BR>
<DT CLASS="dt-description"><A NAME="ecreadexdr"></A><A NAME="@default107"></A><B>ec_read_exdr <I>channel</I></B><DD CLASS="dd-description"><BR>
reads an EXDR-term from the given channel and returns it
 as a Tcl data structure, according to its type. Note that,
 since Tcl does not have a strong type system, some typing
 information can get lost in this process (e.g. string vs. atom).<BR>
<BR>
<DT CLASS="dt-description"><A NAME="@default108"></A><B>ec_tcl2exdr <I>data ?format?</I></B><DD CLASS="dd-description"><BR>
This is the low-level primitive to encode the given <I>data</I> and
 type information in <I>format</I> to an EXDR-string which is
 suitable for sending over communication links to ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> or
 other agents which can decode EXDR-format.
 If no format is specified, it defaults to S (string).<BR>
<BR>
<DT CLASS="dt-description"><A NAME="@default109"></A><B>ec_exdr2tcl <I>exdr_string</I></B><DD CLASS="dd-description"><BR>
This is the low-level primitive to decode an EXDR-string.
 It returns a Tcl data structure, according to the type information
 encoded in the EXDR-string. Note that,
 since Tcl does not have a strong type system, some typing
 information can get lost in this process (e.g. string vs. atom).
</DL>
Since Tcl is an untyped language, all commands which create EXDR terms
accept, in addition to the data, an optional <B>format</B> argument
which allows all EXDR data types to be specified.
The syntax is as follows:
<BLOCKQUOTE CLASS="quote">
<TABLE BORDER=1 CELLSPACING=0 CELLPADDING=1>
<TR><TD ALIGN=left NOWRAP><B>To create EXDR type</B></TD>
<TD ALIGN=left NOWRAP><B>use &lt;format&gt;</B></TD>
<TD ALIGN=left NOWRAP><B>data required</B></TD>
</TR>
<TR><TD ALIGN=left NOWRAP>String</TD>
<TD ALIGN=left NOWRAP>S</TD>
<TD ALIGN=left NOWRAP>string (binary)</TD>
</TR>
<TR><TD ALIGN=left NOWRAP>String</TD>
<TD ALIGN=left NOWRAP>U</TD>
<TD ALIGN=left NOWRAP>string (utf8)</TD>
</TR>
<TR><TD ALIGN=left NOWRAP>Integer</TD>
<TD ALIGN=left NOWRAP>I</TD>
<TD ALIGN=left NOWRAP>integer</TD>
</TR>
<TR><TD ALIGN=left NOWRAP>Double</TD>
<TD ALIGN=left NOWRAP>D</TD>
<TD ALIGN=left NOWRAP>double</TD>
</TR>
<TR><TD ALIGN=left NOWRAP>List</TD>
<TD ALIGN=left NOWRAP>[&lt;<B>formats</B>&gt;]</TD>
<TD ALIGN=left NOWRAP>fixed length list</TD>
</TR>
<TR><TD ALIGN=left NOWRAP>List</TD>
<TD ALIGN=left NOWRAP>[&lt;<B>formats</B>&gt;*]</TD>
<TD ALIGN=left NOWRAP>list</TD>
</TR>
<TR><TD ALIGN=left NOWRAP>Struct</TD>
<TD ALIGN=left NOWRAP>(&lt;<B>formats</B>&gt;)</TD>
<TD ALIGN=left NOWRAP>fixed list, first elem functor name</TD>
</TR>
<TR><TD ALIGN=left NOWRAP>Struct</TD>
<TD ALIGN=left NOWRAP>(&lt;<B>formats</B>&gt;*)</TD>
<TD ALIGN=left NOWRAP>list, first elem functor name</TD>
</TR>
<TR><TD ALIGN=left NOWRAP>Anonymous Variable</TD>
<TD ALIGN=left NOWRAP>_</TD>
<TD ALIGN=left NOWRAP>string "_"</TD>
</TR></TABLE>
</BLOCKQUOTE>
Here are some examples that show which Tcl data/format pair corresponds
to which ECL<SUP><I>i</I></SUP>PS<SUP><I>e</I></SUP> term (the curly brackets are just Tcl quotes and
not part of the format string):
<BLOCKQUOTE CLASS="quote"><PRE CLASS="verbatim">
Tcl data        Tcl format      Eclipse term

hello           S               "hello"
hello           ()              hello
123             S               "123"
123             I               123
123             D               123.0
123             ()              '123'
{a 3 4.5}       {[SID]}         ["a", 3, 4.5]
{a 3 4.5}       S               "a 3 4.5"
{1 2 3 4}       {[I*]}          [1, 2, 3, 4]
{f 1 2 3}       {(I*)}          f(1,2,3)
{is _ {- 1 2}}  {(_(II))}       _ is 1-2
</PRE></BLOCKQUOTE>
<HR>
<A HREF="embroot023.html"><IMG SRC ="previous_motif.gif" ALT="Previous"></A>
<A HREF="embroot016.html"><IMG SRC ="contents_motif.gif" ALT="Up"></A>
<A HREF="embroot025.html"><IMG SRC ="next_motif.gif" ALT="Next"></A>
</BODY>
</HTML>
